package com.diandian.CoolCo.schulte;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;

public class TickView extends View{
	
	private Paint paint = new Paint();
	private int   count = 3;
	private float density;

	public TickView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		Resources resources = getContext().getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
		density = dm.density;
	}

	public TickView(Context context, AttributeSet attrs) {
		super(context, attrs);
		Resources resources = getContext().getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
		density = dm.density;
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		
		int paddingLeft = getPaddingLeft();
		int paddingTop = getPaddingTop();
		int paddingRight = getPaddingRight();
		int paddingBottom = getPaddingBottom();
		int contentWidth = getWidth() - paddingLeft - paddingRight;
		int contentHeight = getHeight() - paddingTop - paddingBottom;
		int cx = contentWidth / 2;
		int cy = contentHeight / 2;
		
		double scale = (float) ((float) contentWidth/480 );
		float small_radius = (float) (144.2 * scale);
		float big_radius   = (float) (166.6 * scale);
		float stroke_width = (float) (10.5 * scale);
		
		paint.setAntiAlias(true);
		paint.setColor(getResources().getColor(R.color.tick));
		paint.setStrokeWidth(stroke_width);
		paint.setStyle(Style.STROKE);
		
		canvas.drawCircle(cx, cy, small_radius, paint);
		canvas.drawCircle(cx, cy, big_radius, paint);
		
		
//		paint.setAntiAlias(true);
//		paint.setColor(getResources().getColor(R.color.tick));
//
//		double scale = (float) ((float) contentWidth / 480 * 0.7);
//
//		paint.setStrokeWidth(10.5 * scale);
//		paint.setStyle(Style.STROKE);
//		
//		canvas.drawCircle(cx, cy, 206 * scale, paint);
//		canvas.drawCircle(cx, cy, 238 * scale, paint);
		
		paint.setStrokeWidth((float) (17.85 * scale));
		paint.setStyle(Style.FILL);
		paint.setTextSize((float) (220.5 * scale));

		Typeface face = Typeface.createFromAsset(getContext().getAssets(),
				"fonts/Roboto-Italic.ttf");
		paint.setTypeface(face);
		
		if (count == 0) {
			paint.setStrokeWidth((float) (16.8 * scale));
			paint.setTextSize((float) (176.4 * scale));
			canvas.drawText("go", ((float)(cx - 220.5 * scale / 4 - 35 * scale)), ((float)(cy + 220.5
					* scale / 4 - 21 * scale)), paint);
		} else {
			canvas.drawText(String.valueOf(count), ((float)(cx - 220.5 * scale / 4 - 3.5 * scale)), ((float)(cy + 220.5
					* scale / 4 + 3.5 * scale)), paint);
		}
//		paint.setStrokeWidth((float) (30 * scale*0.7 * 0.85));
//		paint.setStyle(Style.FILL);
//		paint.setTextSize(315 * scale);
//		
//		Typeface face = Typeface.createFromAsset(getContext().getAssets(),
//				"fonts/Roboto-Italic.ttf");
//		paint.setTypeface(face);
//		
//		if (count == 0) {
//			paint.setStrokeWidth((float) (30 * scale * 0.8));
//			paint.setTextSize((float) (315 * scale * 0.8));
//			canvas.drawText("go", cx - 315 * scale / 4 - 50 * scale, cy + 315
//					* scale / 4 - 30 * scale, paint);
//		} else {
//			canvas.drawText(String.valueOf(count), cx - 315 * scale / 4 - 5 * scale, cy + 315
//					* scale / 4 + 5 * scale, paint);
//		}
	}
	
	public void setCount(int count) {
		this.count = count;
	}
}
